﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL_Class;

namespace NLLSite.Administrator.UserControl
{
    public partial class ManageSlide : System.Web.UI.UserControl
    {
        Slide sli = new Slide();
        SLIDE slid;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            Txtimgslide.Text = string.Empty;
            TxtimgThb.Text = string.Empty;
            Txtdes.Text = string.Empty;
            Txtlink.Text = string.Empty;
            lblchk.Text = string.Empty;
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            Response.Redirect("ThemSlide.aspx");
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Panel1.Visible = true;
            Txtimgslide.Text = ((Label)GridView1.SelectedRow.FindControl("Label1")).Text;
            TxtimgThb.Text = ((Label)GridView1.SelectedRow.FindControl("Label2")).Text;
            Txtdes.Text =HttpUtility.HtmlDecode(GridView1.SelectedRow.Cells[2].Text);
            Txtlink.Text = GridView1.SelectedRow.Cells[4].Text;
            if (((CheckBox)GridView1.SelectedRow.Cells[3].Controls[0]).Checked)
            {
                Cbxsta.Checked = true;
            }
            else { Cbxsta.Checked = false; }
        }

        protected void Cbxdele_CheckedChanged(object sender, EventArgs e)
        {

            for (int i = 0; i < GridView1.Rows.Count; i++)
            {

                if (Cbxdele.Checked)
                {
                    ((CheckBox)GridView1.Rows[i].FindControl("Cbx")).Checked = true;
                }
                else
                {
                    ((CheckBox)GridView1.Rows[i].FindControl("Cbx")).Checked = false;
                }
            }
        }

        protected void BtnDele_Click(object sender, EventArgs e)
        {
            Panel1.Visible = false;
            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox cb = (CheckBox)row.FindControl("Cbx");
                if (cb != null && cb.Checked)
                {
                    sli.DeleteSlide(Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value));
                }
            }
            GridView1.DataBind();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            slid = new SLIDE();
            slid.ID = Convert.ToInt32(GridView1.DataKeys[GridView1.SelectedIndex].Value);
            slid.SlideImage = Txtimgslide.Text;
            slid.ThumbImage = TxtimgThb.Text;
            slid.Description = Txtdes.Text;
            slid.Link = Txtlink.Text;
            if (Cbxsta.Checked)
            {
                slid.Status = true;
            }
            else { slid.Status = false; }
            lblchk.Text = sli.UpdateSlide(slid);
            GridView1.DataBind();
        }
    }
}